package monte;

import java.util.ArrayList;

/**
 * 比赛队伍生成器
 */
public class TeamGenerator {

    /**
     * 可以生成队伍
     *
     * @param teamNum 生成的队伍数量
     * @return 返回生成的队伍数组
     */
    public ArrayList<Team> generateTeams(int teamNum, PowerGenerator powerGenerator) {
        ArrayList<Team> teams = new ArrayList<>(teamNum);
        for (int i = 0; i < teamNum; i++) {
            teams.add(new Team("Team" + (i + 1), powerGenerator.generatePower()));
        }
        return teams;
    }

    public interface PowerGenerator {
        double generatePower();
    }

    public static class RandomGenerator implements PowerGenerator {
        private double fluctuate;
        private double baseline;

        public RandomGenerator(double fluctuate, double baseline) {
            this.fluctuate = fluctuate;
            this.baseline = baseline;
        }

        @Override
        public double generatePower() {
            return (Math.random() * fluctuate) + baseline;
        }
    }

    public static class EqualRatioGenerator implements PowerGenerator {

        private double value;
        private double changeRates;

        public EqualRatioGenerator(double baseline, double changeRates) {
            this.value = baseline;
            this.changeRates = changeRates;
        }

        @Override
        public double generatePower() {
            double val = value;
            value /= changeRates;
            return val;
        }
    }
}
